package formulation.taglibs;

import java.io.IOException;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import db.ICommonObject;

public class CopyOfListTag extends TagSupport
{
    private static final long serialVersionUID = 1L;
    
    private String id;
    private List<ICommonObject> list;
    
    public void setList(List<ICommonObject> list) {
        this.list = list;
    }
    
    public void setId(String id) {
        this.id = id;
    }

    @Override
    public int doStartTag() throws JspException
    {
        JspWriter out = pageContext.getOut();
        try
        {
            out.print("<ul id=\"" + id + "\"class=\"topnav\"><li>");
            if (list.size() > 0) {
                out.print("<em id=\"" + list.get(0).getId().toString() + "\">");
                out.print(list.get(0).getName());
                out.print("</em>");
            }
            else {
                out.print("<em id=\"0\">null</em>");
            }
            out.print("<ul class=\"subnav\">");
            for (int i = 0; i < list.size(); i++) {
                ICommonObject obj = list.get(i);
                out.print("<li><em id=\"" + obj.getId().toString() + "\">");
                out.print(obj.getName());
                out.print("</em></li>");
                //out.print("<option id='" + obj.getId() + "'>");
            }
            out.print("</ul></li>");
            out.print("</ul>");
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return SKIP_BODY;
    }
    
    

}
